<template>
  <div v-text="value"></div>
</template>

<script>
import dayjs from 'dayjs'
const dateFormat = 'YYYY-MM-DD';
const dateTimeFormat = dateFormat + ' HH:mm:ss';
export default {
  name: 'IDate',
  props: {
    option: {
      type: Object,
      required: false,
      default: () => {
        return {
          withTime: false
        };
      }
    },
    fieldValue: {
      type: [String, Date],
      required: false,
      default: () => {
        return undefined;
      }
    }
  },
  computed: {
    value() {
      return (typeof this.fieldValue === 'string') ? this.fieldValue : 
        (this.fieldValue instanceof Date ? 
          (this.option.withTime ? dayjs(this.fieldValue).format(dateTimeFormat) : dayjs(this.fieldValue).format(dateFormat)) : '未知');
    }
  }
}
</script>

<style scoped>

</style>